package com.zx.learn.flink.source;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


/**
 * 使用env.fromElements()，这种方式也支持Tuple，自定义对象等复合形式。
 * todo：fromElements不可以支持多个并行度
 */
public class FromElementDemo {
    public static void main(String[] args) throws Exception {
        //直接获取当前的运行环境
        //StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port", 8081);//设置webui的端口号
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);

        //The parallelism of non parallel operator must be 1.(fromElements不可以支持多个并行度)
        //DataStreamSource<Integer> nums = env.fromElements(1, 2, 3, 4, 5, 6, 7).setParallelism(10);
        DataStreamSource<Integer> nums = env.fromElements(1, 2, 3, 4, 5, 6, 7);
        DataStreamSource<Tuple2<String, Integer>> tuple = env.fromElements(
                new Tuple2<>("spark", 2),
                new Tuple2<>("hadoop", 1)
        );
        System.out.println("FromElementDemo创建的DataStream的并行度为："+nums.getParallelism());
        nums.print();
        tuple.print();
        env.execute();
    }
}
